/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

import java.util.ArrayList;

import javax.swing.JTabbedPane;
import client.Talk;


/**
 *
 * @author tomek
 */
public class HistoryDisplayGui extends JFrame {

    ArrayList<Talk> talkList;
    JTabbedPane tabbedPane = new JTabbedPane();
    
    public HistoryDisplayGui(ArrayList<Talk> t) {
        super("History");
        
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        
        talkList = t;
        
        for(int i = 0; i < talkList.size(); i++) {
            JPanel p = createPanel(talkList.get(i));
            tabbedPane.addTab(talkList.get(i).getNames(), p);
            
        }
        add(tabbedPane);
        
        //The following line enables to use scrolling tabs.
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    }
    
    public JPanel createPanel(Talk t) {
        JPanel panel = new JPanel();
        
        JTextArea textArea = new JTextArea();
        String[] messages = t.getFullMessages();
    
        textArea.setFont(new Font("Serif", Font.ITALIC, 14));
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setEditable(false);
        
        for(int i = 0; i < messages.length; i++) {
            if(messages[i] != null) textArea.append(messages[i]+"\n");
        }
        
        JScrollPane areaScrollPane = new JScrollPane(textArea);
        areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        areaScrollPane.setPreferredSize(new Dimension(650, 350));
        
        panel.add(areaScrollPane);
        
        
        
        return panel;
    }
    
    public void showGui() {
        pack();
        super.setVisible(true);
    }

}
